#ifndef __HEAD_H__
#define __HEAD_H__

#include <mysql/mysql.h>
#include <string.h>
#include <stdio.h>
#include<stdlib.h>

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
#include <time.h>
#include <pwd.h>
#include <grp.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/time.h>
#include <pthread.h>
#include <setjmp.h>
#include <sys/time.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <sys/uio.h>
#include <arpa/inet.h>
#include <sys/shm.h>
#include <sys/epoll.h>
#define ARGS_CHECK(argc, val) \
    if(argc != val) { \
        printf("error args\n"); \
        return -1; \
    } 


#define ERROR_CHECK(ret, retVal, funcName) { \
    if(ret == retVal) { \
        perror(funcName); \
        return -1; \
    } \
}

#define THREAD_ERROR_CHECK(ret, funcName) \
    do { \
        if (0 != ret) { \
            printf("%s : %s\n", funcName, strerror(ret)); \
        } \
    }while(0)

typedef struct conf1
{
	
	char ip[17];
	struct conf1* next;
}Conf_t,*pConf_t;
typedef struct confNode
{
	int size;
	pConf_t phead;
	pConf_t ptail;
}confNode_t,*pconfNode_t;

//截取字符串前的空格
void Ltrim(char *string);
void Rtrim(char *string);
pConf_t load(const char *pconfName, pConf_t* conf);
int selectData(char* fileid,char *table, char *type, char *data);
void cd(int fd,char* data,char* parent_id,char* userid);
void ls(int fd,char *arrb,char* userId);
void pwd(char *userId,int fd,char* pwd);
int serverLogin(int sockFd);  //服务端登录
int query(char *username, char *salt, char *pwd);  //在数据库中查找，返回用户的id
typedef struct{
    char username[30]; //用户名字
    char cmd[30];   //用户命令
}record,*pRecord;

int logrecord(char *username,char *cmd,int x);
int insert_log(record re_log);
int check_log();
int selectData1(char* fileid,char *table, char *type, char *data,int fd);
int selectFilename(char *name,char* userID);
int selectpwd(char* query,int fd);
int selectls(char *query,int fd);
int selectcd(char* query,char* files);
int updatePwd(char* query);
char* updateparent_id(char *query);
int deleteMyfile(int fd,char* userid,char* filename);
int moveCnt(char* query);
int deleteCnt(char* query);
int selectStrcmp(char* userid,char* md5);
int selectMkdir(char* parent_id,char* userId,char* filename);
int Mkdir(char* query);
int insertMkdir(char* query);




int serverGets(int sockFd, int curDirID, int ownerID);
int insertNewfile(int parentID, char *filename, int ownerID, char *md5str, int filesize, char type);
int Compute_file_md5(const char *file_path, char *value);
int selectMd5(char* md5,char* userid);
#endif
